/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */

package space.model;

import java.util.Arrays;
import javax.media.opengl.GL3bc;
import jinngine.geometry.Geometry;
import jinngine.math.Matrix3;
import jinngine.math.Matrix4;
import jinngine.math.Vector3;
import jinngine.physics.Body;
import space.gl.RenderContext;
import space.stream.StructureInput;

/**
 *
 * @author Pierre Labatut
 */
public class ConvexHull implements MdlGeometry {

    final String name;
    final Matrix4 matrix;
    final Vector3[] vectors;

    public ConvexHull(StructureInput di) {
        name = di.readString();
        matrix = di.readObject(Matrix4.class);
        vectors = di.readArray(Vector3.class);
    }

    public Drawable optimize(GL3bc gl) {
        return this;
    }

    public void draw(RenderContext gl) {
    }

    public void debug(GL3bc gl) {
    }

    public void dispose(GL3bc gl) {
    }

    public void addGeometry(Body body) {
        final Geometry g = new jinngine.geometry.ConvexHull("hull", Arrays.asList(vectors), 0.);
        final Matrix3 r = new Matrix3(matrix);
        final Vector3 t = new Vector3(matrix.a14, matrix.a24, matrix.a34);
        body.addGeometry(r, t, g);
    }
}
